import { defineStore } from 'pinia'

interface Sidebar {
  opened: boolean
}

interface AppState {
  sidebar: Sidebar
}

export const useAppStore = defineStore('app', {
  state: (): AppState => ({
    sidebar: {
      opened: localStorage.getItem('sidebarStatus') ? 
        !!+localStorage.getItem('sidebarStatus') : true
    }
  }),
  actions: {
    toggleSidebar() {
      this.sidebar.opened = !this.sidebar.opened
      if (this.sidebar.opened) {
        localStorage.setItem('sidebarStatus', '1')
      } else {
        localStorage.setItem('sidebarStatus', '0')
      }
    }
  }
})